﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Model;
using System.Data.SqlClient;
using WCF_Client.MovieReference;


namespace BioBooking
{
    public partial class ManageMovies : Form
    {
        //MovieController movieController;
        private MovieServiceClient movieService;
        
        public ManageMovies()
        {
            InitializeComponent();
            //movieController = new MovieController();
            movieService = new MovieServiceClient();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime newDate = new DateTime();
                newDate = DateTime.Parse(txtRelaseDate.Text);
                double newDouble = Convert.ToDouble(txtRanking.Text);
                Console.WriteLine(txtSerialNo.Text + txtLength.Text + txtTitle.Text + txtGenre.Text + newDate + newDouble);
                movieService.CreateMovie(txtSerialNo.Text, txtLength.Text, txtTitle.Text, txtGenre.Text, newDate, newDouble);  

            }
            catch (Exception ex)
            {

                Console.WriteLine("Caught: " + ex.Message);

            }
                
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            foreach (Movie m in movieService.FindAllMovies())
            {
                listBox1.Items.Add(m);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Movie tempMovie = (Movie)listBox1.SelectedItem;
            try
            {
                movieService.DeleteMovie(tempMovie.SerialNo);
                listBox1.Items.Remove(listBox1.SelectedItem);
            }
            catch (SqlException sqle)
            {

            }
        }
    }
}
